package main

import (
	"fmt"
)

func twoSum_bad(nums []int, target int) []int {
	for index, num := range nums {
		for index_2, num_2 := range nums[index+1:] {
			fmt.Println(index, index_2, num, num_2)
			if num+num_2 == target {
				return []int{index, index_2 + index + 1}
			}
		}
	}

	return []int{0, 0}
}

func twoSum(nums []int, target int) []int {
	NumMap := make(map[int]int)

	for index, num := range nums {
		NumMap[num] = index
	}

	for index, num := range nums {
		if index_2, ok := NumMap[target-num]; ok && index != index_2 {
			return []int{index, index_2}
		}
	}
	return []int{0, 0}
}

func twoSum2(nums []int, target int) []int {
	NumMap := make(map[int]int, len(nums))
	for index, num := range nums {
		if index_2, ok := NumMap[target-num]; ok && index != index_2 {
			return []int{index, index_2}
		}
		NumMap[num] = index
	}
	return []int{0, 0}
}

func twoSumGo(nums []int, target int) []int {

}

func main() {
	target := 6
	nums := []int{3, 2, 4}
	result := twoSum2(nums, target)
	fmt.Println("result:", result)
}
